package com.tlgen.logging.repository;

import com.tlgen.logging.domain.Log;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

/**
 * @author: tlgen
 * @Discription:
 */
@Repository
public interface LogRepository extends JpaRepository<Log, Long>, JpaSpecificationExecutor<Log> {

    /**
     * 根据日志类型查询
     * @param logType
     */
    @Query(nativeQuery = true, value = "delete from log where log_type = ?1")
    @Modifying
    void deleteByLogType(String logType);

    /**
     * 获取一个时间段的ip记录
     * @param data1
     * @param date2
     * @return
     */
    @Query(value = "select count(*) from (select request_ip from log where create_time between ?1 and ?2 group by request_ip) as s", nativeQuery = true)
    Long findIp(String data1, String date2);
}
